<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <img id="mySrc" />
  <script>
    const srcImg = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1605722900651&di=9b53918af2fe5dec0e29cc50054a512d&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20181130%2F62e70b6fbc7c457db7ca392bd856fed1.jpeg';
    const srcLocal = './lalala.jpg';
    const setImgSrc = (function () {
      const imgDom = document.getElementById('mySrc');
      return {
        setSrc: function (src) {
          imgDom.src = src
        }
      }
    })()
    const proxyImg = (function () {
      const img = new Image();
      img.onload = function () {
        setImgSrc.setSrc(srcImg)
      }
      return {
        setSrc: function (src) {
          img.src = src;
          setImgSrc.setSrc(srcLocal)
        }
      }
    })()

    proxyImg.setSrc(srcImg)

  </script>
</body>

</html>